
	var $selectedItems = {};

	$(function(){
		window.widget_selected_tables = new widgetSelectItems('div-selected-tables', tableList);
		
		$(".div-table").click(selectTableToShow);
		
		$('#selectMenu').click(function(){
			var arrTableIds = [];
			
			for(var id in $selectedItems)
				arrTableIds.push(id);
				
			var jsonForPost = {tableIds : arrTableIds};
			var strUrl  = 'orderTable.action';
			jQuery.ajax ({
				url: strUrl,
				contentType:"application/json",
				type: "POST",
				cache: false,
				processData: false,
				dataType: "json",
				data: JSON.stringify(jsonForPost),
			    success: function(jsonRes)
			    {
					alert(jsonRes.status);
					location.href='../menu/Show.action';
			    }
		    });
		});
	});
	
	function selectTableToShow(e){
		var id = e.srcElement.tableId;
		var table = widget_selected_tables.getItem(id);
		var htmlTable = [];
		htmlTable.push('<div class="div-selected-table"><span class="span-selected-table-name">');
		htmlTable.push(table.number);
		htmlTable.push('</span><span class="span-selected-table-status">');
		htmlTable.push(table.status);
		htmlTable.push('</span><span class="span-selected-table-remove" menuItemId="');
		htmlTable.push(id);
		htmlTable.push('" onclick="removeTable(this.menuItemId);"></span></div>');
		var item = $(htmlTable.join(''));
		$selectedItems[id] = item;
		$("#div-selected-tables").append(item);
	}
	
	function removeTable(id){
		$selectedItems[id].remove();
	}
	